/**
 * Created with IntelliJ IDEA.
 * Description:二分查找
 * User: bjc
 * Date: 2025-11-14
 * Time: 21:52
 */
public class Test01_binarySearch {
    public int search(int[] nums, int target) {
        int len = nums.length;
        int left = 0,right = len - 1;
        while(left <= right){
            int mid = (left + right) / 2;
            if(nums[mid] == target) return mid;
            else if(nums[mid] < target){
                left = mid + 1;
            }else if(nums[mid] > target){
                right = mid - 1;
            }
        }
        return -1;
    }
}
